package books.ThinkingInJava.src.Chapter18;

import books.ThinkingInJava.src.Tools.FileKit;
import books.ThinkingInJava.src.Tools.Output;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
import java.util.regex.Pattern;

/**
 * @author bloodcolding
 * @since 12/27/2018 11:56 AM
 */
public class TestStream {

    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        if (scan.hasNext()) {
            Output.println(new TestStream().read(scan.nextLine()));
        }
    }

    public String read(String path) throws IOException {
        if (path == null) {
            return null;
        }
        path = FileKit.filePathTransfer(path);
        StringBuilder stringBuilder = new StringBuilder();
        String s;
        BufferedReader bufferedReader = new BufferedReader(new FileReader(path));
        Pattern pattern = Pattern.compile("^\\d+$");
        while ((s = bufferedReader.readLine()) != null) {  //使用括号括起来的部分是一个单独的变量
            if (pattern.matcher(s).matches()) {
                stringBuilder.append(s.toUpperCase());
            }
        }
        bufferedReader.close();
        return stringBuilder.toString();
    }
}

